﻿using System;
using System.Collections.Generic;
using MLSharp.Utilities;

namespace MLSharp.Filters
{
	/// <summary>
	/// Removes a specified list of attributes from a
	/// data set.
	/// </summary>
	public class AttributeExcluderFilter : AttributeFilterBase
	{
		#region Public Constructors

		/// <summary>
		/// Filters the specified attributes.
		/// </summary>
		/// <param name="attributeNames">The names of attributes to remove (this parameter is case sensitive).</param>
		public AttributeExcluderFilter(params string[] attributeNames) : base(attributeNames)
		{
			
		}

		#endregion

		#region Public Methods

		/// <summary>
		/// Applies the filter to the specified data set.
		/// </summary>
		/// <param name="dataSet">The data set to transform.</param>
		public override void Transform(IDataSet dataSet)
		{
			//If there are no attributes to filter, just return.
			if (AttributeNames.Length == 0)
			{
				return;
			}

			for (int i=0; i < dataSet.Attributes.Count; i++)
			{
				//If the current attribute is on the list of attributes to exclude, 
				//remove it.
				if (Array.IndexOf(AttributeNames, dataSet.Attributes[i].Name) != -1)
				{
					dataSet.Attributes.RemoveAt(i);
					i--;
				}
			}
		}

		#endregion
	}
}
